/**
 * 事件派发类
 * Dispatcher.ins.addEventListener(Complete,  onComplete , this);
 * Complete：事件类型
 * onComplete：响应事件
 * 
 * 事件监听：
 * Dispatcher.ins.addEventListener("complete", onComplete, this);
 * 事件派发：
 * Dispatcher.ins.dispatchEvent(new GameEvent("complete",data:any));
 * data:数据携带
 */
class Dispatcher extends egret.EventDispatcher {
    static lock: boolean = true;
    private static _instance: Dispatcher; 
    public constructor() {
        if (Dispatcher.lock) throw "please use ins()";
        super();
    }

    // 注意此处是public static, this指向Dispatcher类, 而不是它的实例
    // 因此, _instance必须定义为静态成员才能获取
    public static get ins(): Dispatcher {
        if (this._instance == null || this._instance == undefined) {
            Dispatcher.lock = false;
            this._instance = new Dispatcher();
            Dispatcher.lock = true;
        }
        return this._instance;
    }
}
// 自定义事件
class GameEvent extends egret.Event {
    public constructor(type: string, data?: any, bubbles: boolean=false, cancelable: boolean=false) {
        super(type, bubbles, cancelable, data);
    }
}